
#include "World.h"

World::World(void)
{
}

World::World( size_t const& row, size_t const& column )
: board(row, column)
{
	initDecipline();
}

World::~World(void)
{
}

void World::show() const
{
	using std::cout;
	using std::endl;
	//std::vector<int> const * buffer = board.toVector();
	Board::InfoType buffer = board.toInfoType();
	for (size_t r = 1; r != buffer.getRow() - 1; ++r)
	{
		for (size_t c = 1; c != buffer.getColumn() - 1; ++c)
		{
			cout << (buffer.at(r, c) ? '*' : ' ') << ' ';
		}
		cout << endl;
	}
}

void World::refresh()
{
	Board tmp(getRow(), getColumn());
	for (size_t row = 0; row != getRow(); ++row)
		for (size_t column = 0; column != getColumn(); ++column)
		{
			int tmpValue = deciplines.useDeciplines(board.getNeighborsInfo(row, column));
			tmp.setSquare(row, column, tmpValue > 0 ? 1:0);
		}
	board.swap(tmp);
}

void World::initDecipline()
{
	deciplines.addDecipline(new EmptyDecipline());
	deciplines.addDecipline(new OccupyDecipline());
	deciplines.addDecipline(new KeepDecipline());
}